package com.nuorui.module.gen.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nuorui.common.utils.GenUtils;
import com.nuorui.module.gen.entity.ColumnEntity;
import com.nuorui.module.gen.entity.GenConfig;
import com.nuorui.module.gen.entity.InfoRmationSchema;
import com.nuorui.module.gen.mapper.SysGenMapper;
import com.nuorui.module.gen.service.SysGenService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@AllArgsConstructor
public class SysGenServiceImpl extends ServiceImpl<SysGenMapper, InfoRmationSchema> implements SysGenService {

    private final SysGenMapper sysGenMapper;
    private final GenUtils     genUtils;

    @Override
    public void generatorCode(GenConfig config, String[] trimTable) {
        for (String tableName : config.getGenTable()) {
            //查询表信息
            InfoRmationSchema table = sysGenMapper
                .queryTableList(new QueryWrapper<InfoRmationSchema>().eq("tableName", tableName));
            //查询列信息
            List<ColumnEntity> columns = sysGenMapper.queryColumns(new QueryWrapper<ColumnEntity>().eq("tableName", tableName));
            //生成代码
            genUtils.generatorCode(config, table, columns, trimTable);
        }
    }
}
